package com.jasmine.bjstkserver.server.plan;

import com.jasmine.auth.util.AuthUtil;
import com.jasmine.bjstkserver.server.plan.model.PlanDTO;
import com.jasmine.bjstkserver.server.plan.model.PlanReq;
import com.jasmine.core.dto.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author : jasmineXz
 */
@RestController
@RequestMapping("/plan")
public class PlanController {


    @Autowired
    private PlanService planService;


    @GetMapping
    public R findList(PlanReq planReq) {
        planReq.setUserId(AuthUtil.getUserId());
        return R.ok(planService.findList(planReq));
    }


    /**
     * 新增计划
     * @param planDTO 计划参数
     */
    @PostMapping
    public R insert (@RequestBody PlanDTO planDTO) throws Exception {
        planDTO.setUserId(AuthUtil.getUserId());
        planService.insert(planDTO);
        return R.ok();
    }


    /**
     * 删除计划
     * @param planReq 计划ID
     */
    @DeleteMapping
    public R delete (@RequestBody PlanReq planReq) {
        planService.delete(planReq.getPlanId());
        return R.ok();
    }
}
